﻿using System.Data;


namespace Dapper.Library
{
    /// <summary>
    /// 排序
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class Order<T> : Option<T>, IOrder<T>
    {
        protected Order(IDbConnection conn, SqlProvider sqlProvider) : base(conn, sqlProvider)
        {

        }

        protected Order(IDbConnection conn, SqlProvider sqlProvider, IDbTransaction dbTransaction) : base(conn, sqlProvider, dbTransaction)
        {

        }

        /// <summary>
        /// 排序
        /// </summary>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="field"></param>
        /// <returns></returns>
        public virtual Order<T> OrderBy(OrderByType orderBy, string field)
        {
            if (field != null)
                SqlProvider.SetContext.OrderbyList.Add(orderBy, field);
            return this;
        }

        /// <summary>
        /// Asc排序
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        public virtual Order<T> OrderByAsc(string field)
        {
            if (field != null)
                SqlProvider.SetContext.OrderbyList.Add(OrderByType.Asc, field);
            return this;
        }

        /// <summary>
        /// Desc排序
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        public virtual Order<T> OrderByDesc(string field)
        {
            if (field != null)
                SqlProvider.SetContext.OrderbyList.Add(OrderByType.Desc, field);
            return this;
        }
    }
}
